package com.example.service_statistics.controller;

import com.example.common.commonsutils.R;
import com.example.service_statistics.entity.StatisticsDaily;
import com.example.service_statistics.service.StatisticsDailyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author:tjf
 * @Description:
 */
@Tag(name = "统计分析控制器")
@RequestMapping("/statisticsservice")
@RestController
public class StatisticsController {
    @Resource
    private StatisticsDailyService statisticsService;
    @Operation(description = "统计指定日期的数据并生成")
    @PostMapping("/{day}")
    public R createStatisticsData(@PathVariable("day") String day){
        StatisticsDaily statisticsData = statisticsService.saveStatisticsData(day);
        return R.ok().data("data", statisticsData);
    }
    @Operation(description = "查询指定时间段的统计日数据")
    @GetMapping("/{begin}/{end}")
    public R queryStatisticsData(@PathVariable("begin") String begin,
                                 @PathVariable("end") String end){
        Map<String, Object> result = statisticsService.queryStatisticsData(begin, end);
        return R.ok().data("result", result);
    }
}
